package com.example.my_bookkeeping;

import androidx.test.ext.junit.runners.AndroidJUnit4;

import com.example.my_bookkeeping.data.manager.CategoryManager;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.util.ArrayList;
import static org.junit.Assert.*;

@RunWith(AndroidJUnit4.class)
public class DeleteCategoryTest {
    private final CategoryManager categoryManagerInstance = CategoryManager.getInstance();

    @After
    @Before
    public void setUp() {
        categoryManagerInstance.reset();
    }

    @Test
    public void testDeleteCategory() {
        // 获取初始分类列表（复制一份，避免直接操作原始列表）
        ArrayList<String> initialExpenseCategories = categoryManagerInstance.getExpenseCategoryList();

        // 确保有可删除的分类
        assertFalse("支出分类列表不应为空", initialExpenseCategories.isEmpty());

        // 选择要删除的分类
        String categoryToDelete = initialExpenseCategories.get(0);

        // 删除选中的分类
        categoryManagerInstance.deleteCategory(categoryToDelete, false);

        // 验证分类已被删除
        ArrayList<String> updatedExpenseCategories = categoryManagerInstance.getExpenseCategoryList();
        assertFalse("分类应该已被删除", updatedExpenseCategories.contains(categoryToDelete));
        assertEquals("分类列表长度应该减少1", initialExpenseCategories.size() - 1, updatedExpenseCategories.size());

        // 验证其他分类保持不变
        for (String category : initialExpenseCategories) {
            if (!category.equals(categoryToDelete)) {
                assertTrue("其他分类应该保持不变", updatedExpenseCategories.contains(category));
            }
        }
    }
}